package com.xinyue.ext.reader.bean;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import com.xinyue.ext.data.FieldData;
import com.xinyue.ext.exception.BeanException;
import com.xinyue.ext.reader.ParamHolder;

public class PropertyProcess extends BeanContext{
	//私有构造器
	private PropertyProcess() {
	}
	//私有内部类
	private static class SingletonHolder{
        private static PropertyProcess instance = new PropertyProcess();  
    }
	/**
	 * 获得实例对象
	 * @param holder 
	 */
	public static PropertyProcess getInstance(ParamHolder holder) {
		BeanContext.holder = holder;
		return SingletonHolder.instance;
	}
	
	
	/**
	 * 读取property中的信息
	 * param e entity
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void read(Element e) throws BeanException {
		List<Element> es = e.elements(property_);
		if(es == null || es.size() == 0) {
			throw new BeanException("property标签未定义", holder.getException());
		}
		
		//属性集合
		List<FieldData> fields = new ArrayList<FieldData>();
		
		for (Element pro: es) {
			//公共属性
			FieldData field = commonRead(pro);
			
			fields.add(field);
		}

		holder.getEntity().setFields(fields);
	}
}
